<?php
//ini_set('display_errors', 'On');
//error_reporting(E_ALL);
if(isset($_GET["id"])) {$identifiant = $_GET["id"];} else{$identifiant = "";}
if(isset($_GET["ligne"])) {$ligne = $_GET["ligne"];} else{$ligne = "";}

require_once '../include/class.pdoSio.inc.php';
require '../dompdf/dompdf_config.inc.php';

$pdo = PdoSio::getPdoSio();
$etudiants = $pdo->requeteSelection('SELECT * FROM utilisateurs WHERE id_utilisateur = '.$ligne);
$experience_prof = $pdo->requeteSelection('SELECT * FROM cv_experience_prof WHERE id_utilisateur = '.$ligne);
$formation = $pdo->requeteSelection('SELECT * FROM cv_formation WHERE id_utilisateur = '.$ligne);
$informatique = $pdo->requeteSelection('SELECT * FROM cv_informatique WHERE id_utilisateur = '.$ligne);
$interet = $pdo->requeteSelection('SELECT * FROM cv_interet WHERE id_utilisateur = '.$ligne);
$langue = $pdo->requeteSelection('SELECT * FROM cv_langue WHERE id_utilisateur = '.$ligne);
$photo = $pdo->requeteSelection("SELECT * FROM cv_photo WHERE id_utilisateur =".$ligne);
$content = "<html>
    <head>
        <title>Test</title>
    </head>
    <body>
        <div class='entete'>
            ".$etudiants[0]["nom"]." ".$etudiants[0]["prenom"]."<br>".
            $etudiants[0]["adresse_rue"]."<br>".
            $etudiants[0]["adresse_cp"]." ".$etudiants[0]["adresse_ville"]."<br>".
            $etudiants[0]["tel_professionnel"]."<br>".
            $etudiants[0]["tel_personnel"]."<br>".
            $etudiants[0]["mail"]."<br>".
            $etudiants[0]["site_web"]."<br>".
            $etudiants[0]["annee_entree_promotion"]."-".$etudiants[0]["annee_sortie_promotion"].
        "</div>
        <div class='experience'>
            <h2>Expérience professionnelle</h2>
            ";
            foreach ($experience_prof as $uneExperience) {
                $puce = "<li>".$uneExperience["anneeDeb"]."-".$uneExperience["anneeFin"]." ".$uneExperience["poste"].", ".$uneExperience["fonction"]."</li>";
                $content .= $puce; 
            }
        $content .= "</div>
        <div class='formation'>
            <h2>Formation</h2>
            ";
            foreach ($formation as $uneFormation) {
                $puce = "<li>".$uneFormation["AnneeDeb"]."-".$uneFormation["AnneeFin"]." ".$uneFormation["Diplome"].", ".$uneFormation["Etab"]."</li>";
                $content .= $puce;
            }
        $content .= "</div>
        <div class='informatique'>
            <h2>Informatique</h2>
            ";
            foreach ($informatique as $uneInfo) {
                $puce = "<li>".$uneInfo["competence"]."</li>";
                $content .= $puce;
            }
        $content .= "</div>
        <div class='interet'>
            <h2>Centre d'intérêt</h2>
            ";
            foreach ($interet as $unInteret) {
                $puce = "<li>".$unInteret["musique"].", ".$unInteret["sport"].", ".$unInteret["autre"]."</li>";
                $content .= $puce;
            }
        $content .= "</div>
        <div class='langue'>
            <h2>Langue</h2>
            ";
            foreach ($langue as $uneLangue) {
                $puce = "<li>".$uneLangue["langue"].", ".$uneLangue["niveau"]."</li>";
                $content .= $puce;
            }
        $content .= "</div>";
//        <div class='photo'>";
//            foreach ($photo as $unePhoto) {
//                file_put_contents("./styles/img/".$ligne.".jpg",$unePhoto['photo']);
//                $content .= "<img src='./styles/img/".$ligne.".jpg' />";
//            }
//        $content .= "</div>
        $content .= "<style>
            body {font-family: 'Times New Roman', serif;}
            .entete {padding-bottom: 60px;}
            h2 {padding-bottom: 10px; text-decoration: underline;}
            li {padding-left: 50px;}
            .experience {padding-bottom: 20px;}
            .formation {padding-bottom: 20px;}
            .informatique {padding-bottom: 20px;}
            .interet {padding-bottom: 20px;}
            .langue {padding-bottom: 20px;}
            .photo {margin-top: 10px; margin-right: 10px;}
        </style>
    </body>
</html>";
    
$dompdf = new DOMPDF(); 
$dompdf->load_html($content);
$dompdf->render();
$dompdf->stream("CV_".$etudiants[0]["prenom"]."_".$etudiants[0]["nom"].".pdf");
